<template>
  <div :class="'page-' + urlFrom">
    <div class="float-btn" :class="getShowBuyCard && !checkOwner && getCustomerId ? 'high-space' : ''">
      <ul style="position:relative">
        <li v-for="(item, index) in floatList" :key="index">
          <template v-if="urlFrom === 'home'">
            <button v-if="item.linkType === 1012 && enterpriseCustomerServiceAuthority === 1"
              :send-message-title="memberInfo.nickname + '的V客主页'" plain send-message-img="https://veekrayimg.joinsun.vip/images/share-s-picture.png"
              show-message-card="true" send-message-path="/pages/home/main" open-type="contact" class="contactBtn hidden-submit button-icon"
              :session-from="'7moor|'+ customerInfo.nickname + '|' + customerInfo.avatar +'|'+ customField"></button>
          </template>
          <template v-if="urlFrom === 'shopDetail'">
            <button v-if="item.linkType === 1012 && enterpriseCustomerServiceAuthority === 1"
              :send-message-title="goodsData.title" plain :send-message-img="goodsImg"
              show-message-card="true"
              :send-message-path="'/pages/shop/detail/main?memberId=' + getMemberId + '&goodsId=' + goodsData.goodsId + '&goodsType=' + goodsData.goodsType + '&shareMemberId=' + getCustomerId"
              open-type="contact" class="contactBtn hidden-submit button-icon" 
              :session-from="'7moor|'+ customerInfo.nickname + '|' + customerInfo.avatar +'|'+ customField"></button>
          </template>
          <div style="position:relative">
            <img
              v-if="item.imgUrl"
              :src="item.imgUrl + '?imageView2/2/w/120'"
              @click="linkTo(item)"
              class="width-58 height-58"/>
            <!-- 小B客服消息未读数 -->
            <span :class="unread['sellerUnread'] > 99 ? 'news-tag-style1': 'news-tag-style2'" v-if="item.linkType === 1011 && personalType === 0 && getCustomerId !== getMemberId && unread['sellerUnread'] > 0">{{unread.sellerUnread}}</span>
            <span :class="unread['buyerUnread'] > 99 ?'news-tag-style1' : 'news-tag-style2'" v-if="item.linkType === 1011 && personalType === 1 && unread['buyerUnread'] > 0">{{unread['buyerUnread']}}</span>
          </div>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
  import { getMemberInfo } from '@/api/home'
  import { getAuthority } from '@/api/common'
  export default {
    data() {
      return {
        memberInfo: {},
        customerInfo: {},
        goods: {},
        goodsImg: '',
        personalType: '',
        customField: {}, // 企业客服自定义传参
        unread: {
          sellerUnread: '', // 买家收到 卖家的消息(未读消息数)
          buyerUnread: '' // 卖家收到 买家的消息(未读数)
        },
        shopCustomerServiceAuthority: 1, // 小B客服增值功能 0关闭 1开启
        enterpriseCustomerServiceAuthority: 1 // 企业客服增值功能 0关闭 1开启
      }
    },
    props: {
      floatList: {
        type: Array,
        default: []
      },
      urlFrom: {
        type: String,
        default: ''
      },
      goodsData: {
        type: Object,
        default: {}
      }
    },
    onShow() {
      this.goodsImg = ''
      this.goodsData = {}
      this.unread['sellerUnread'] = +this.$pt.getStorageSync('imUnreadSeller') || +this.getImUnreadSeller
      this.unread['buyerUnread'] = +this.$pt.getStorageSync('imUnreadBuyer') || +this.getImUnreadBuyer
      this.data()
    },
    mounted() {
      this.goodsImg = ''
      this.goodsData = {}
      this.unread['sellerUnread'] = +this.$pt.getStorageSync('imUnreadSeller') || +this.getImUnreadSeller
      this.unread['buyerUnread'] = +this.$pt.getStorageSync('imUnreadBuyer') || +this.getImUnreadBuyer
      setTimeout(() => {
        this.data()
      }, 100)
      // 获取用户状态 买家：0   卖家：1
      this.personalType = this.$pt.getStorageSync('personalType')
      this.getAuthority()
    },
    methods: {
      data() {
        this.initMemberInfo()
        if (this.urlFrom === 'shopDetail') {
          if (this.goodsData.shareImageUrl) {
            this.goodsImg = this.goodsData.shareImageUrl
          }
          if (!this.goodsData.shareImageUrl && this.goodsData.images) {
            this.goodsImg = this.goodsData.images[0]
          }
        }
      },
      // 运营总后台 增值功能权限获取
      getAuthority() {
        getAuthority().then(res => {
          this.shopCustomerServiceAuthority = res.data.shopCustomerServiceAuthority
          this.enterpriseCustomerServiceAuthority = res.data.enterpriseCustomerServiceAuthority
        }).catch(err => {
          console.log(err)
        })
      },
      getCaption(obj) {
        let index = obj.lastIndexOf('=')
        obj = obj.substring(index + 1, obj.length)
        return obj
      },
      linkTo(item) {
        this.$emit('linkTo', item)
      },
      initMemberInfo() {
        getMemberInfo(this.getMemberId).then((response) => {
          if (response.isError) return
          this.memberInfo = response.data
        }).catch(() => {
        })
        if (this.getRoleType === 2) return
        getMemberInfo(this.getCustomerId).then((response) => {
          if (response.isError) return
          this.customerInfo = response.data
        }).catch(() => {
        })
      }
    }
  }
</script>

<style scoped lang="less">
  // 返回我的店铺按钮
  .page-home{
    .float-btn {
      bottom: 85px;
      &.high-space{
        bottom: 85px;
      }
    }
  }
  .float-btn {
    z-index: 100;
    position: fixed;
    bottom: 133px;
    right: 8px;
    width: 58px;
    height: 58px;
    text-align: center;
    &.high-space{
      bottom: 133px;
    }
    ul{
      li{
        position: relative;
        &:first-child{
          margin-bottom: 10px;
        }
        img{
          border-radius: 100px;
        }
        .contactBtn {
          background-color: transparent!important;
          position: absolute;
          width:100%;
          height:100%;
          left: 0;
          top: 0;
          z-index: 999;
          border-color: transparent!important;
          border: none!important;
        }
      }
    }
  }
      .news-tag-style1{
        position: absolute;
        font-size: 18rpx;
        background: #f00;
        color: #fff;
        border-radius: 5px;
        top: 0px;
        right: 4rpx;
        padding: 0px 4rpx;
      }
      .news-tag-style2 {
        position: absolute;
        font-size: 18rpx;
        background: #f00;
        color: #fff;
        border-radius: 50%;
        top: 0rpx;
        right: 4rpx;
        width: 30rpx;
        height: 30rpx;
        text-align: center;
      }
</style>
